﻿using Autofac;
using Autofac.Integration.Mvc;
using RepositoryPattern.Controllers;
using RepositoryPattern.Infrastructure;
using RepositoryPattern.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace RepositoryPattern
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {

            var container = new ContainerBuilder();
            container.RegisterType<DALContext>().As<IDALContext>();

            container.RegisterType<CatalogService>().As<ICatalogService>();
            //ControllerBuilder.Current.SetControllerFactory(new DefaultControllerFactory());
            container.RegisterControllers(typeof(MvcApplication).Assembly);
            var build = container.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(build));
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
    }
}
